I'm so sorry for the double post, but it seems I cannot edit my previous one.
So, it seems I made a mistake in my last post. The program was crashing because I forgot to call the set_enemies function. The correct code for game.h is this:
game.h
Code:
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
#include "startup.h"
#include "timer.h"
#include "player.h"
#include "tileeditor.h"
#include "enemyeditor.h"
int game()
{
bool quit = false;
bool tileedit = false;
if( init() == false ) return 1;
if( load_files() == false ) return 2;
timer fps;
player player1( 50 , 50 );
tile * tiles[ TOTAL_TILES ];
enemy * enemies[ TOTAL_TILES ];
if( set_tiles( tiles ) == false ) return 4;
if( set_enemies( enemies ) == false ) return 4;
while( quit == false )
{
fps.start();
scrolling_background();
if( tileedit ) editor_show( current_tile );
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_KEYDOWN )
{
if( event.key.keysym.sym == SDLK_t ) tileedit = !tileedit;
}
if( event.type == SDL_QUIT ) quit = true;
if( tileedit == false ) player1.control();
else if( tileedit ) editor_control( tiles );
}
if( tileedit == false )
{
player1.jump();
scrolling_background();
player1.move( tiles );
////////////////////////// PROBLEM IS HERE //////////////////////////
//for( int e = 0 ; e < TOTAL_TILES ; e++ ) enemies[e]->move( tiles );
///////////////////////////////////////////////////////////////////////////////////
player1.player_camera();
}
else editor_camera();
for( int t = 0 ; t < TOTAL_TILES ; t++ ) tiles[t]->show();
for( int e = 0 ; e < TOTAL_TILES ; e++ ) enemies[e]->show();
if( tileedit == false ) player1.show();
if( SDL_Flip( screen ) == -1 ) return 5;
if( fps.get_ticks() < 1000 / FPS ) SDL_Delay( ( 1000 / FPS ) - fps.get_ticks() );
}
editor_save( tiles );
cleanup( tiles );
cleanup( enemies );
return 0;
}
#endif // GAME_H_INCLUDED
As you can see, there seems to be a problem every time I try to call enemy::move(tile * tiles[])
The debugger gives me a segmentation fault, wich, from what I understand, means that the function is trying to access the wrong piece of memory. I can't find where exactly is the problem though, so, once again, I need some help figuring it out.
Sorry for asking so many things, and, as always, thank you in advance.